﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;

namespace LoA.Shared.Physics {
	/// <summary>
	/// Stan fizyczny
	/// </summary>
	public struct PhysicalState {
		private readonly PhysicalModel physicalModel;
		//private Matrix orientation;
		//private Vector3 position;
		//private float force;
		//private Vector3 direction;
		//private GravitationState gravitation;
		//private float potentialEnergy;
		//private float kineticEnergy;

		public PhysicalState(PhysicalModel physicalModel) {
			this.physicalModel = physicalModel;
			this.Orientation = default(Matrix);
			this.position = default(Vector3);
			this.Force = default(float);
			this.Direction = default(Vector3);
			this.Gravitation = default(GravitationState);
			this.PotentialEnergy = default(float);
			this.KineticEnergy = default(float);

		}

		/// <summary>
		/// Orientation (matrix) in 3D world space
		/// </summary>
		public Matrix Orientation;
		/// <summary>
		/// Position (vector3) in 3D world space
		/// </summary>
		private Vector3 position;
		public Vector3 Position {
			get { return position; }
			set { this.position = value; }
		}
		/// <summary>
		/// Siła ( newton )
		/// </summary>
		public float Force;
		/// <summary>
		/// Kierunek / Zwrot ( normal vector3 )
		/// </summary>
		public Vector3 Direction;
		/// <summary>
		/// Stan grawitacyjny
		/// </summary>
		public GravitationState Gravitation;
		/// <summary>
		/// Energia potencjalna ( joule )
		/// </summary>
		public float PotentialEnergy;
		/// <summary>
		/// Energia kinetyczna ( joule )
		/// </summary>
		public float KineticEnergy;


		/// <summary>
		/// Szybkość ( m / s )
		/// </summary>
		public float Speed { get { return this.physicalModel.Mass != 0 ? this.Force / this.physicalModel.Mass : 0; } }
		/// <summary>
		/// Prędkość ( vector3 m / s)
		/// </summary>
		public Vector3 Velocity { get { return this.Direction * this.Speed; } }

		/// <summary>
		/// Przyśpieszenie
		/// </summary>
		public Vector3 Acceleration { get { return this.Direction * this.Force / this.physicalModel.Mass; } }
	}
}
